package com.fx.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;

/**
 * @Auther: EDZ
 * @Date: 2018-7-10 13:56:
 * @Email: 你的邮箱
 * 概要说明：该类干嘛用的
 **/
public class LocationUtil {

    public static JSONObject getLocationByLatAndLng(double lat,double lng){
        JSONObject jsonObject = new JSONObject();
        try {
            String address = HttpUtil.get("http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=" + lat + "," + lng + "&output=json&pois=1&ak=9bf61ba9ef1c13b849348d2cbcf27a8e");
            JSONObject addressJson  = JSONObject.parseObject(address.substring(address.indexOf("(") + 1, address.lastIndexOf(")")));
            JSONObject result = addressJson.getJSONObject("result");
            jsonObject.put("province",result.getJSONObject("addressComponent").getString("province"));
            jsonObject.put("city",result.getJSONObject("addressComponent").getString("city"));
            jsonObject.put("street",result.getJSONObject("addressComponent").getString("district"));
        }catch (Exception e){
            e.printStackTrace();
        }
        return jsonObject;
    }

    public static void main(String[] args) {
       String url = "http://wwww.baidu.com/upUser111";
       if(url.contains("="))
            System.out.println(url.split("=")[1]);
    }
}
